/**
    ATClab - scriptable Air Traffic Control simulations.
    Copyright (C) 2010 openatclab@gmail.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
**/

#ifndef __ATC_CANVAS_TOOLS_HDR__
#define __ATC_CANVAS_TOOLS_HDR__

#include <q3canvas.h>
#include "atc_types.h"
#include "canvas_types.h"


namespace atc {

	//
	// class declarations
	//
	class AircraftAgent;
	class AircraftSprite;
	class Canvas;
	class WayPointSprite;


	//
	// atc::BearingRangeLine
	//

	class BearingRangeLine : public QObject {
		Q_OBJECT

	public:
		BearingRangeLine( Canvas * );
		~BearingRangeLine();

	public:
		void anchor( AircraftSprite * );
		void anchor( WayPointSprite * );
		void anchor( const QPoint & );
		void hook( AircraftSprite * );
		void hook( WayPointSprite * );
		void hook( const QPoint & );
		void unhook();
		void move_by( double, double );
		bool hit( const QPoint & )const;

	public:
		void update();

	public slots:
		void update_anchor( double, double );
		void update_hook( double, double );
		void reanchor( bool );
		void rehook( bool );

	private:
		void initialize( double, double );
		void update_data();

	private:
		Canvas           *_canvas;
		AircraftSprite   *_anchor;
		AircraftSprite   *_hook;
		Q3CanvasLine      *_line;
		Q3CanvasLine      *_X1;
		Q3CanvasLine      *_X2;
		Q3CanvasText      *_range;
		Q3CanvasText      *_bearing;
		Q3CanvasText      *_time;
		Q3CanvasRectangle *_box;
		
		int _lsize;

	};


	//
	// atc::BRLLine
	//
	class BRLLineSprite : public Q3CanvasLine {

	public:
		BRLLineSprite( Q3Canvas *c ) : Q3CanvasLine( c ) {}
		~BRLLineSprite() { hide(); }

	public: //virtual
		int rtti() const { return CanvasItem::RTTI_BRLLINE; }
	
	};

	//
	// atc::BRLData
	//
	class BRLDataSprite : public Q3CanvasRectangle {

	public:
		BRLDataSprite( BearingRangeLine *, const QRect &, Q3Canvas * ); 
		~BRLDataSprite();

	public: //virtual
		int rtti() const { return CanvasItem::RTTI_BRLDATA; }

	public:
		BearingRangeLine* select();
		void kill();

	private:
		BearingRangeLine *_brl;
	
	};


	//
	// atc::VectorTool
	//
	class VectorTool {

	public:
		VectorTool( Canvas *, AircraftSprite * );
		~VectorTool();

	public:
		void update();
		void set_end( int, int );
		void action();

		bool is_valid() const;

		AircraftSprite *aircraft() const { return _aircraft; }

	private:
		AircraftSprite *_aircraft;
		Q3CanvasLine    *_vector;

	};

};

#endif
